import { extend } from 'umi-request';
import { history } from 'umi';

// export async function query(): Promise<any> {
//   return request('/api/users');
// }


/** 异常处理程序 */
const errorHandler = (error: { response: Response }): Response => {

  const { response } = error;

  if (response && response.status) {
    const { status, url } = response;
    if(status==401){
      // notification.error({
      //   message: `token已失效`,
      //   description: '请重新登录',
      // });
      history.replace({
        pathname: '/',
      });
    }
  } else if (!response) {

  }
  return response;
};

const request = extend({
  errorHandler, // 默认错误处理
  credentials: 'include', // 默认请求是否带上cookie
  headers:{
    'Content-Type': 'application/x-www-form-urlencoded',
    'authorization':`${sessionStorage.getItem('token')}`
  },
});

export async function queryCurrent(): Promise<any> {
  return request('/xwyl/currentUser',{method: 'POST',  headers:{
    'Content-Type': 'application/x-www-form-urlencoded',
    'authorization':`${sessionStorage.getItem('token')}`
  },});
}
export async function queryPrice(): Promise<any> {
  return request('/xwyl/priceGrade/getPriceGrade',{method: 'POST',  headers:{
    'Content-Type': 'application/x-www-form-urlencoded',
    'authorization':`${sessionStorage.getItem('token')}`
  },});
}



// export async function queryNotices(): Promise<any> {
//   return request('/api/notices');
// }
